/** m2settings is a GUI to configure Maven 2 settings.xml 
 * 
 *  Copyright (C) 2007 Regis Decamps <decamps@users.sf.net>
 * 
 *  This file is part of m2settings.
 *
 *  m2settings is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version. 
 *
 *  Foobar is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *  or read it online http://www.gnu.org/licenses/gpl.txt
 *
 **/
package info.decamps.m2settings;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import org.exolab.castor.xml.MarshalException;
import org.exolab.castor.xml.ValidationException;

public class SettingsXMLFileBinder extends SettingsXMLBinder {
	private File settingsFile;
	/**
         * Constructs a settings binder to the config file specified by settingsDotXml
         **/
	public SettingsXMLFileBinder(File settingsDotXML) {
		settingsFile=settingsDotXML;
	}
	
        /**
         *Constructs a settings binder using the default config file.
         *It settings.xml does not exist, it will be created.
         */
        public SettingsXMLFileBinder() throws FileNotFoundException, MarshalException, ValidationException {
            this(getDefaultSettingsDotXml());
        }
        
	public void loadSettings() throws FileNotFoundException, MarshalException, ValidationException {
		FileReader fr=new FileReader(settingsFile);
		readSettings(fr);
	}
	
	public void saveSettings() throws IOException, MarshalException, ValidationException {
		FileWriter fw=new FileWriter(settingsFile);
		writeSettings(fw);
	}
        
        public static File getDefaultSettingsDotXml() {
            return new File(System.getProperty("user.home")+"/.m2/settings.xml");
        }
}